//
//  ShipListItem.m
//  SpaceStorm
//
//  Created by 祥 雍 on 13-6-17.
//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
//
//
//  战斗UI中的船舰列表的元素

#import "ShipListItem.h"


@implementation ShipListItem
@synthesize index = _index;

/**
	创建一个船舰列表元素的实例
	@param iconFrameName icon的frameName
	@param name 船舰的名称
	@param maxShield 最大护盾值
	@param maxArmoured 最大护甲值
	@param maxHp 最大结构值
	@returns 元素的实例
 */
+(id) itemWithIcon:(NSString*)iconFrameName
              name:(NSString*)name
         maxShield:(int)maxShield
       maxArmoured:(int)maxArmoured
             maxHp:(int)maxHp
             index:(int)index
{
    return [[[self alloc] initWithIcon:iconFrameName name:name maxShield:maxShield maxArmoured:maxArmoured maxHp:maxHp index:index] autorelease]; 
}

-(id) initWithIcon:(NSString*)iconFrameName 
              name:(NSString*)name 
         maxShield:(int)maxShield 
       maxArmoured:(int)maxArmoured
             maxHp:(int)maxHp
             index:(int)index
{
    if( (self=[super init])) 
    {
        //纪录逻辑index
        _index = index;
        
        //初始化背景
        _bg = [ToggleSprite spriteWithActive:@"BGActive.png" unactive:@"BGUnActive.png"];
        [self addChild:_bg];
        self.contentSize = _bg.contentSize; //设置触摸感应区域
        
        //icon
        _icon = [CCSprite spriteWithSpriteFrameName:iconFrameName];
        _icon.position = ccp(30, 45);
        [self addChild:_icon];
        
        //名字
        _name = [CCLabelTTF labelWithString:name fontName:@"Marker Felt"  fontSize:11];
        _name.anchorPoint = ccp(0, 1);
        _name.position = ccp(6, 28);
        [self addChild:_name];
        
        //护盾值及背景
        _shieldBlood = [SlowBloodStretch bloodStretchWithBG:@"bloodBG.png" slow:@"redSlowBloodBG.png" blood:@"shieldBlood.png"  width:41 isLeft:YES];
        _shieldBlood.position = ccp(13, 6);
        [self addChild:_shieldBlood];
        
        //护甲值及背景
        _armouredBlood = [SlowBloodStretch bloodStretchWithBG:@"bloodBG.png" slow:@"redSlowBloodBG.png" blood:@"armouredBlood.png"  width:41 isLeft:YES];
        _armouredBlood.position = ccp(13, 10);
        [self addChild:_armouredBlood];
        
        //hp值及背景
        _hpBlood = [SlowBloodStretch bloodStretchWithBG:@"bloodBG.png" slow:@"redSlowBloodBG.png" blood:@"hpBlood.png"  width:41 isLeft:YES];
        _hpBlood.position = ccp(13, 14);
        [self addChild:_hpBlood];

    }
    
    return self;
}

/**
	设置Item是不是被选中
	@param isSelect 是不是选中
 */
-(void) selectItem:(BOOL)isSelect
{
    [_bg setActive:isSelect];
}

@end
